import com.sun.org.apache.regexp.internal.recompile;


public class Board {
	protected static int size;
	boolean[] array;
	boolean[][] board;
	
	public Board(int size) {
		this.size = size;
		array = new boolean[size];
		board = new boolean[size][size];
	}
	
	public String toString() {
		String out = "";
		for(int i=0;i<size;i++) {
			for(int j=0; j<size; j++) {
				if(board[i][j])
					out += "X";
				else
					out += " ";
			}
			out += "\n";
		}
		return out;
	}
	
	public boolean addPoint(int x, int y) {
		if(this.board[x-1][y-1])
			return false;
		this.board[x-1][y-1] = true;
		return true;
	}
	
	public class TicTacToe extends Board{
		boolean[][] boardX;
		boolean[][] boardY;
		
		public TicTacToe() {
			super(3);
			boardX = new boolean[Board.size][Board.size];
			boardY = new boolean[Board.size][Board.size];
		}
		
		public String toString() {
			String out= "";
			for(int i=0;i<Board.size;i++) {
				for(int j=0; j<Board.size; j++) {
					if(this.boardX[i][j])
						out += "X";
					else if(this.boardY[i][j])
						out += "Y";
					else
						out += "";
				}
				out += "\n";
			}
			return out;
		}
		
		public String won() {
			// X
			//vertically win
			for (int i=0; i<Board.size; i++) {
				int vertical = 0;
				for (int j=0; j<Board.size; j++) {
					if(this.boardX[i][j])
						vertical++;
				}
				if (vertical == 3)
					return "X won the game";
			}
			
			//horizontal win
			for (int i=0; i<Board.size; i++) {
				int horizontal = 0;
				for (int j=0; j<Board.size; j++) {
					if(this.boardX[j][i])
						horizontal++;
				}
				if (horizontal == 3)
					return "X won the game";
			}
			
			//diagonal win
			
			if(this.boardX[0][0] && this.boardX[1][1] && this.boardX[2][2])
				return "X won the game";
			if(this.boardX[0][2] && this.boardX[1][1] && this.boardX[2][1])
				return "X won the game";
			
			
			//Y
			//vertically win
			for (int i=0; i<Board.size; i++) {
				int vertical = 0;
				for (int j=0; j<Board.size; j++) {
					if(this.boardY[i][j])
						vertical++;
				}
				if (vertical == 3)
					return "Y won the game";
			}
			
			//horizontal win
			for (int i=0; i<Board.size; i++) {
				int horizontal = 0;
				for (int j=0; j<Board.size; j++) {
					if(this.boardY[j][i])
						horizontal++;
				}
				if (horizontal == 3)
					return "Y won the game";
			}
			
			//diagonal win
			
			if(this.boardY[0][0] && this.boardY[1][1] && this.boardY[2][2])
				return "Y won the game";
			if(this.boardY[0][2] && this.boardY[1][1] && this.boardY[2][1])
				return "Y won the game";
			
			//game draw
			int total = 0;
			for (int i=0; i<Board.size; i++) {
				for (int j=0; j<Board.size; j++) {
					if(this.boardY[j][i] || this.boardX[i][j])
						total++;
				}
			}
			if (total == 9)
				return "game draw";
			
			
			return null;
		}
	
		public boolean addPointX(int x, int y) {
			if(this.boardX[x-1][y-1] || this.boardY[x-1][y-1])
				return false;
			this.boardX[x-1][y-1] = true;
			return true;
		}
		
		public boolean addPointY(int x, int y) {
			if(this.boardX[x-1][y-1] || this.boardY[x-1][y-1])
				return false;
			this.boardY[x-1][y-1] = true;
			return true;
		}
		
	}
	
	public class Point{
		int x;
		int y;
		
		public Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}
}